package com.soup.view.component;

import com.soup.view.value.ColorValue;
import com.soup.view.value.SizeValue;

import javax.swing.*;
import java.awt.*;

public class TopNavigation extends JPanel {
    private static final long serialVersionUID = 1L;
    private JLabel title = new JLabel();
    private int count = 0,center = 0;
    public TopNavigation(int width){
        this.setBounds(0, 0, width, SizeValue.TopNavigationHeight);
        this.setBackground(ColorValue.TopNavigationBackground);
        this.setLayout(null);
        this.center = (int)width/2;
        title.setBounds(1, 2, center, this.getHeight()-4);
        title.setFont(new Font("幼圆", Font.BOLD, SizeValue.TopNavigationHeightFont));
        title.setForeground(ColorValue.TopNavigationForeground);
        title.setBorder(BorderFactory.createMatteBorder(0, 5, 0, 0, ColorValue.TopNavigationBackground));
        super.add(title);
    }

    public void add(JComponent component) {
        component.setBounds(this.getWidth()-this.getHeight()-count*this.getHeight(), 2, this.getHeight()-4, this.getHeight()-4);
        super.add(component);
        component.setBackground(ColorValue.TopNavigationBackground);
        component.setForeground(ColorValue.TopNavigationForeground);
        component.setFocusable(false);
        component.setFont(new Font("幼圆", Font.BOLD, SizeValue.TopNavigationHeightFont));
        component.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 0, Color.WHITE));
        count ++;
    }

    public void setTitle(String title) {
        this.title.setText(title);
    }
}
